<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="stripes"
	uri="http://stripes.sourceforge.net/stripes.tld"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>My First Stripe</title>


<style type="text/css">
body {
	
	background-image: url("img/new.jpg");
}

input.error {
	background-color: yellow;
}

#bg {
	width: 500px;
	height: 300px;
	margin: 150px auto;
	background-color: #FFCC00;
}

table {
	margin: 50px auto;
}

table tr {
	font-weight: bold;
	font-family: cursive;
	font-size: large;
}

.input {
	border-color: black;
	width: 200px;
	font-family: cursive;
	font-weight: bold;
}
</style>

<script type="text/javascript">
	function checkInCorrect() //判断用户名和密码是否为空
	{

		if (document.getElementById("userName").value == "") {
			alert('请输入用户名！');
			document.getElementById("userName").focus();
			return false;
		}
		if (document.getElementById("userPass").value == "") {
			alert('请输入密码！');
			document.getElementById("userPass").focus();
			return false;
		} else {
			saveInfo();
			return true;
		}
	}

	saveInfo = function() {
		try {
			var isSave = document.getElementById("remember").checked; //保存按键是否选中

			if (isSave) {
				var usernm = document.getElementById("userName").value;
				var userpsw = document.getElementById("userPass").value;
				if (usernm != "" && userpsw != "") {
					SetCookie(usernm, userpsw);
				}
			} else {
				SetCookie("", "");
			}
		} catch (e) {

		}
	}

	function SetCookie(usern, psw) {
		var Then = new Date();
		Then.setTime(Then.getTime() + 1866240000000);
		document.cookie = "username=" + usern + "%%" + psw + ";expires="
				+ Then.toGMTString();
	}

	function GetCookie() {
		var nmpsd;
		var nm;
		var psd;
		var cookieString = new String(document.cookie);
		var cookieHeader = "username=";
		var beginPosition = cookieString.indexOf(cookieHeader);
		cookieString = cookieString.substring(beginPosition);
		var ends = cookieString.indexOf(";");
		if (ends != -1) {
			cookieString = cookieString.substring(0, ends);
		}
		if (beginPosition > -1) {
			nmpsd = cookieString.substring(cookieHeader.length);
			if (nmpsd != "") {
				beginPosition = nmpsd.indexOf("%%");
				nm = nmpsd.substring(0, beginPosition);
				psd = nmpsd.substring(beginPosition + 2);
				document.getElementById("userName").value = nm;
				document.getElementById("userPass").value = psd;
				if (nm != "" && psd != "") {
					document.getElementById("remember").checked = true;
				}
			}
		}
	}
</script>



</head>
<body onload="document.getElementById('userPass').focus();GetCookie();">
	<h1 style="color: #FFCC00;">Welcome to J2eeshop Website</h1>



	<div id="bg">


		<form action="/j2eeshop/actions/Login.action" id="Login"
			onsubmit="return checkInCorrect();">
			<stripes:errors />

			<table>
				<tr>
					<td>UserName:</td>
					<td><input type="text" name="login.userName" id="userName"
						class="input" /></td>
				</tr>
				<tr>
					<td>PassWord:</td>
					<td><input type="password" name=login.userPass id="userPass"
						class="input" /></td>
				</tr>



				<tr>
					<td colspan="2"><input type="checkbox" id="remember" />
						remember me</td>
				</tr>
				<tr>
					<td colspan="2" align="right"><input type="submit"
						value="Login"
						style="width: 100px; height: 35px; font-weight: bold;"
						class="input" /></td>
				</tr>

			</table>
		</form>

	</div>
	
</body>
</html>
